package com.alks.function.service.impl.biocontrol.deptwork;

import cn.hutool.db.sql.SqlUtil;
import com.alks.common.aop.AutoPageAop;
import com.alks.common.data.thread.UserIdThread;
import com.alks.common.utils.BigDecimalUtil;
import com.alks.common.utils.DatabaseUtils.DatabaseUtils;
import com.alks.entity.data.entity.PcFinishOemOutDetail;
import com.alks.entity.data.page.PageRecord;
import com.alks.function.data.dto.biocontrol.webwork.ProdOutTempDto;
import com.alks.function.data.request.biocontrol.webwork.ProdOutRequest;
import com.alks.function.mapper.biocontrol.deptwork.PcFinishOemOutDetailMapper;
import com.alks.function.service.biocontrol.deptwork.IProdOutService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author MS
 * @since 2024/12/4下午2:21
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class ProdOutServiceImpl extends ServiceImpl<PcFinishOemOutDetailMapper, PcFinishOemOutDetail> implements IProdOutService {
    private final PcFinishOemOutDetailMapper outMapper;

    @Override
    @AutoPageAop
    public PageRecord<ProdOutTempDto> tempQuery(ProdOutRequest request) {
        String companyId = UserIdThread.get().getCompanyId();
        /*获取数据*/
        DatabaseUtils.sqlCheck(request.getOrderFile());
        List<ProdOutTempDto> dtoList = outMapper.outTempQuery(request,companyId);
        Map<String, Object> totalMap = outMapper.outTotalQuery(request,companyId);
        return new PageRecord<>(dtoList,totalMap);
    }

    @Override
    public Map<String, Object> back(String vendorSearch, String brandSearch) {
        String companyId = UserIdThread.get().getCompanyId();
        /*获取数据*/
        List<Map<String,String>> vendorList = outMapper.vendorBack(vendorSearch,companyId);
        List<String> brandList = outMapper.brandBack(brandSearch,companyId);
        /*封装数据*/
        Map<String,Object> map = new HashMap<>(2);
        map.put("vendor",vendorList);
        map.put("brand",brandList);
        return map;
    }
}
